package com.chinamoney.wppm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chinamoney.wppm.entity.ProcessDefinitionObj;
import com.chinamoney.wppm.entity.TaskObj;
import com.chinamoney.wppm.service.ActivitiService;

@RestController
public class ActivitiController {

	@Autowired
	private ActivitiService activitiService;
	
	/**
	 * 获取所有已部署的流程定义
	 * @return
	 * 
	 * 说明：
	 * 系统会根据流程文件自动部署流程定义，存储在 act_re_procdef 表中
	 */
	@GetMapping(value="definition")
	public List<ProcessDefinitionObj> getDefinitions() {
		return activitiService.getProcessDefinition();
	}
	
	/**
	 * 删除流程定义
	 */
	@PostMapping(value="deleteDefinition/{definitionId}")
	public void deleteProcessDefinition(@PathVariable("definitionId") String definitionId) {
		activitiService.deleteProcessDefinition(definitionId);
	}
	
	/**
	 * 创建并启动流程
	 * @param definitionId 流程定义ID
	 * @param request
	 * @return
	 */
	@PostMapping(value="start/{definitionKey}")
	public String startProcess(@PathVariable("definitionKey") String definitionKey) {
		activitiService.startProcessByKey(definitionKey);
		return "task/task";
	}
	
	/**
	 * 获取用户的待处理任务
	 * @param userId：用戶ID
	 * @return
	 */
	@GetMapping(value="task/{userId}")
	public List<TaskObj> getTasksByUser(@PathVariable("userId") String userId) {
		return activitiService.getTasksByUser(userId);
	}
	
	/**
	 * 根据用户名字获取任务列表
	 * @param userName
	 * @return
	 */
	@GetMapping(value="task")
	public List<TaskObj> getTasksByUserName(String userName) {
		return activitiService.getTasksByUserName(userName);
	}
	
	/**
	 * 完成任务
	 * @param taskId：任务ID
	 * @param nextApprovers：下一个节点的审批人（id，用;隔开）
	 */
	@PostMapping(value="task/{taskId}")
	public void complitTaskById(@PathVariable("taskId") String taskId, String nextApprovers) {
		activitiService.complitTaskById(taskId, nextApprovers);
	}
	
}
